<ui:composition template="/template/LayoutPadrao.xhtml"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core">

	<ui:define name="titulo">#{cadastroLancamentoBean.editando ? msg.editingEntry : msg.newEntry}</ui:define>

	<ui:define name="conteudo">
		<f:metadata>
			<f:viewParam name="codigo"
				value="#{cadastroLancamentoBean.lancamento}" />
		</f:metadata>

		<h1>#{cadastroLancamentoBean.editando ? msg.editingEntry : msg.newEntry}</h1>
		<h:panelGrid columns="2">
			<h:form>
				<h:button value="#{msg.newBtn}" outcome="NovoLancamento" />
				<h:button value="#{msg.searchBtn}"
					outcome="ConsultaLancamento?faces-redirect=true"
					rendered="#{request.isUserInRole('consulta')}" />
			</h:form>

		</h:panelGrid>
		<h:form id="frm1">
			<h:messages showDetail="false" showSummary="true"
				styleClass="form-messages" errorClass="error" infoClass="info" />
			<h:panelGrid columns="2" styleClass="form-grid"
				columnClasses="label, campo" id="panel">
				<h:outputLabel value="#{msg.type}" for="campoTipo" />
				<h:selectOneRadio id="campoTipo"
					value="#{cadastroLancamentoBean.lancamento.tipo}" required="true"
					label="Tipo do lançamento">
					<f:selectItems value="#{cadastroLancamentoBean.tiposLancamentos}"
						var="tipoLancamento" itemLabel="#{tipoLancamento.descricao}"
						itemValue="#{tipoLancamento}" />
				</h:selectOneRadio>

				<h:outputLabel value="#{msg.person}" for="campoPessoa" />
				<h:selectOneMenu id="campoPessoa"
					value="#{cadastroLancamentoBean.lancamento.pessoa}" required="true"
					label="Pessoa">
					<f:selectItem itemLabel="#{msg.selectOpt}" noSelectionOption="true" />
					<f:selectItems value="#{cadastroLancamentoBean.pessoas}"
						var="pessoa" itemValue="#{pessoa}" itemLabel="#{pessoa.nome}" />
				</h:selectOneMenu>

				<h:outputLabel value="#{msg.description}" for="campoDescricao" />
				<h:inputText id="campoDescricao" size="60"
					value="#{cadastroLancamentoBean.lancamento.descricao}"
					required="true" label="Descrição" />

				<h:outputLabel value="#{msg.value}" for="campoValor" />
				<h:inputText id="campoValor" size="12"
					value="#{cadastroLancamentoBean.lancamento.valor}" required="true"
					label="Valor">
					<f:convertNumber locale="pt_BR" maxFractionDigits="2"
						minFractionDigits="2" />
					<f:validateDoubleRange minimum="0" />
				</h:inputText>

				<h:outputLabel value="#{msg.due_date}" for="campoDataVencimento" />
				<h:inputText id="campoDataVencimento" size="12"
					value="#{cadastroLancamentoBean.lancamento.dataVencimento}"
					required="true" label="Data de Vencimento">
					<f:convertDateTime pattern="dd/MM/yyyy" locale="pt_BR"
						timeZone="GMT-3" />
				</h:inputText>

				<h:outputText></h:outputText>

				<h:panelGroup>
					<h:selectBooleanCheckbox id="campoPago"
						value="#{cadastroLancamentoBean.lancamento.pago}" immediate="true"
						valueChangeListener="#{cadastroLancamentoBean.lancamentoPagoModificado}"
						onchange="jsf.ajax.request(this, event, {execute: '@form', render: 'frm1:panel'})" />
					<h:outputLabel value="#{msg.payedBill}" for="campoPago" />
				</h:panelGroup>

				<h:outputLabel value="#{msg.paymentDate}" for="campoDataPagamento"
					rendered="#{cadastroLancamentoBean.lancamento.pago}" />
				<h:inputText id="campoDataPagamento" size="12"
					value="#{cadastroLancamentoBean.lancamento.dataPagamento}"
					required="false" label="Data de Pagamento"
					rendered="#{cadastroLancamentoBean.lancamento.pago}">
					<f:convertDateTime pattern="dd/MM/yyyy" locale="pt_BR"
						timeZone="GMT-3" />
					<f:validator
						validatorId="com.algaworks.cursojsf2.financeiro.validator.DataFutura" />
					<f:validator
						validatorId="com.algaworks.cursojsf2.financeiro.validator.RequerimentoCondicional" />
					<f:attribute name="checado"
						value="#{cadastroLancamentoBean.lancamento.pago}" />
				</h:inputText>

				<h:outputText></h:outputText>
				<h:commandButton value="#{msg.saveBtn}"
					action="#{cadastroLancamentoBean.salvar}">
					<f:ajax execute="@form" render="@all" />
				</h:commandButton>

			</h:panelGrid>
		</h:form>
	</ui:define>

</ui:composition>
